package com.wuxianedu.wechat.ui.adapter;

import java.util.List;

import com.wuxianedu.wechat.R;
import com.wuxianedu.wechat.bean.MenuItems;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ChatMenuItemAdapter extends BaseAdapter{
	
	private Context context;
	
	private List<MenuItems> list;
	
	private LayoutInflater layoutInflater;
	
	public ChatMenuItemAdapter(Context context,List<MenuItems> list) {
		this.context = context;
		this.list = list;
		layoutInflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView == null){
			holder = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.activity_chat_grid_item, null);
			holder.image_pic = (ImageView) convertView.findViewById(R.id.image_pic);
			holder.tv_menu_name = (TextView) convertView.findViewById(R.id.tv_menu_name);
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}
		
		MenuItems item = list.get(position);
		holder.image_pic.setImageResource(item.getIcon());
		holder.tv_menu_name.setText(item.getName());
		
		return convertView;
	}
	
	class ViewHolder{
		ImageView image_pic;
		TextView tv_menu_name;
	}

}
